<template>
	<view>
		<cu-custom :bgColor="'bg-' + theme.backgroundColor" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">直播间列表</block>
		</cu-custom>
		<scroll-view
			scroll-y
			class="scroll"
			refresher-enabled
			@refresherrefresh="refresherrefresh"
			@scrolltolower="scrolltolower"
			scroll-anchoring
			:lower-threshold="80"
			:style="customBarSty"
			:refresher-triggered="reftriggered">
			<view class="content p-all24">
				<view class="search">
					<view class="cuIcon-search icon"></view>
					<view class="search-ipt">
						<input
							type="text"
							placeholder="请输入直播间名称查询"
							v-model="inputKey"
							confirm-type="search"
							@confirm="keyboardSearch"
							@keyup.enter="keyboardSearch" />
					</view>
					<view class="search-btn" :class="'bg-' + theme.backgroundColor" @click="keyboardSearch"
						>搜索</view
					>
				</view>
				<view class="masters-list">
					<view class="item" v-for="(item, index) in tableList" :key="index">
						<view class="top" @tap.stop="goLive(item)">
							<view class="f30">
								<text>直播间名称：</text>
								<text>{{ item.liveName || "" }}</text>
							</view>
							<view class="cuIcon-right f30"></view>
						</view>
						<view class="num">
							<view class="num-item">
								<view class="f40">{{ item.liveUserNum }}</view>
								<view class="f28 mt10">观看人数</view>
							</view>
						</view>
						<view class="content">
							<view class="col">
								<view class="form-item1">
									<text>直播间编号：</text>
									<text class="ml6">{{ item.liveNo }}</text>
								</view>
							</view>
							<view class="col">
								<view class="form-item">
									<text>发放红包总数 :</text>
									<text class="ml6">{{ item.rewardAllPay || 0 }}</text>
								</view>
								<view class="form-item">
									<text>用户领取红包:</text>
									<text class="ml6"> {{ item.rewardPay || 0 }}</text>
								</view>
							</view>
							<view class="col">
								<view class="form-item">
									<text>发放积分总数 :</text>
									<text class="ml6">{{ item.integralAllNum || 0 }}</text>
								</view>
								<view class="form-item">
									<text>用户领取积分:</text>
									<text class="ml6">{{ item.integralNum || 0 }}</text>
								</view>
							</view>
							<view class="col">
								<view class="form-item">
									<text>发放优惠券总数 :</text>
									<text class="ml6">{{ item.couponAllNum || 0 }}</text>
								</view>
								<view class="form-item">
									<text>用户领取优惠券:</text>
									<text class="ml6">{{ item.couponNum || 0 }}</text>
								</view>
							</view>
							<view class="col">
								<view class="form-item">
									<text>发放奖品总数 :</text>
									<text class="ml6">{{ item.lotteryAllNum || 0 }}</text>
								</view>
								<view class="form-item">
									<text>用户领取奖品:</text>
									<text class="ml6">{{ item.lotteryNum || 0 }}</text>
								</view>
							</view>
						</view>
						<view class="times">
							<view class="col">
								<view class="form-item2">
									<text>直播开始时间：</text>
									<text class="ml6">{{ item.startTime }}</text>
								</view>
							</view>
							<view class="col">
								<view class="form-item2">
									<text>直播结束时间：</text>
									<text class="ml6">{{ item.endTime }}</text>
								</view>
							</view>
						</view>
					</view>
					<view :class="'cu-load ' + (loadmore ? 'loading' : 'over')"></view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
const app = getApp();
import api from "../../../api/api.js";
import util from "@/utils/util.js";
export default {
	data() {
		return {
			theme: app.globalData.theme,
			reftriggered: false,
			customBarSty: `height: calc(100vh - ${this.CustomBar}px);`,
			inputKey: "",
			loadmore: false,
			tzUserId: "",
			page: {
				current: 1,
				size: 5,
				total: 0,
			},
			tableList: [],
		};
	},
	onLoad(options) {
		this.tzUserId = options.tzUserId;
		this.page.current = 1;
		this.tableList = [];
		this.getPage();
	},
	methods: {
		goLive(item) {
			uni.setStorageSync("liveInfoData", item);
			this.$goUrl("/pages_code/pages/datareport/liveInfo/index");
		},
		getPage(fn) {
			this.loadmore = true;
			let para = {
				...this.page,
				liveName: this.inputKey,
				tzUserId: this.tzUserId,
			};
			api.pageLive(util.filterForm(para)).then((res) => {
				let tableList = res.data.records || [];
				this.tableList.push(...tableList);
				if (tableList.length < this.page.size) {
					this.loadmore = false;
				}
				typeof fn === "function" && fn(res);
			});
		},
		keyboardSearch() {
			this.tableList = [];
			this.page.current = 1;
			this.getPage();
		},
		scrolltolower() {
			if (this.loadmore) {
				this.page.current++;
				this.getPage();
			}
		},
		refresherrefresh(e) {
			this.reftriggered = true;
			this.tableList = [];
			this.page.current = 1;
			this.getPage(() => {
				this.reftriggered = false;
			});
		},
	},
};
</script>

<style lang="scss" scoped>
.search {
	padding: 10rpx 0rpx 10rpx 32rpx;
	margin-top: 20rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	background-color: #fff;
	border-radius: 16rpx;
	font-size: 24rpx;

	.icon {
		margin-right: 20rpx;
	}

	.search-ipt {
		flex: 1;

		input {
			border: none;
			outline: none;
			width: 100%;
			font-size: 28rpx;
			height: 70rpx;
			line-height: 70rpx;
		}
	}

	.search-btn {
		padding: 15rpx 32rpx;
		color: #fff;
		border-radius: 16rpx;
		margin-right: 10rpx;
		font-size: 24rpx;
	}
}

.masters-list {
	.item {
		margin: 24rpx 0rpx 0;
		background-color: #fff;
		border-radius: 16rpx;
		padding: 24rpx;

		.top {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 32rpx;
			border-bottom: 2rpx solid #f6f6f6;
		}

		.content {
			margin-top: 32rpx;
			font-size: 24rpx;
			border-top: 2rpx solid #f6f6f6;
			padding-bottom: 32rpx;
			border-bottom: 2rpx solid #f6f6f6;
		}

		.col {
			display: flex;
			align-items: center;
			margin-top: 16rpx;

			.form-item {
				width: 50%;
				color: #666;
			}

			.form-item1 {
				width: 100%;
				color: #666;
			}

			.form-item2 {
				width: 100%;
				color: #999;
			}
		}

		.menu {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			margin-top: 30rpx;

			.menu-btn {
				font-size: 30rpx;
				padding: 20rpx;
				border-radius: 12rpx;
				margin-left: 20rpx;
				background: #ffffff;
				border-radius: 16rpx;
				border: 2rpx solid #fb2e1b;
				font-size: 28rpx;
				color: #fb2e1b;
			}
		}
	}
}

.num {
	display: flex;
	align-items: center;
	justify-content: flex-start;
	margin-top: 32rpx;

	.num-item {
		width: 50%;
		color: #666;
	}
}

.text-gary1 {
	color: #666;
}

.times {
	margin-top: 10rpx;
	font-size: 24rpx;
	color: #999999;
}
</style>
